package yuan.deng.lister;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;
import org.springframework.stereotype.Component;

/**
 * @Description:
 * @Version: V1.0
 */
@Component
public class MyLister implements ChannelAwareMessageListener {

    @Override
    public void onMessage(Message message, Channel channel) throws Exception {
        long tag = message.getMessageProperties().getDeliveryTag();

        try {
            Thread.sleep(1000);
            System.out.println(message.getBody());
            System.out.println("业务逻辑");

            //手动签收

            channel.basicAck(tag,true);
        }catch (Exception e){
            //拒绝签收 第三个参数true就会重回队列重新发送
            channel.basicNack(tag,true, true);
        }
    }
}
